VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "StackIterator"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit

Private vm_HeadItem As StackNode
Private vm_ReverseStack As Stack

Private vm_CurrentItem As StackNode

Public Sub init(ByVal headItem As StackNode)
Set vm_HeadItem = headItem
Set vm_CurrentItem = vm_HeadItem
Set vm_ReverseStack = New Stack
End Sub

Public Function hasPrevious() As Boolean
hasPrevious = Not (vm_ReverseStack.numItems = 0)
End Function

Public Function hasNext() As Boolean
If vm_CurrentItem Is Nothing Then
    hasNext = False
Else
    hasNext = Not (vm_CurrentItem.nextItem Is Nothing)
End If
End Function

Public Sub moveNext()
vm_ReverseStack.push vm_CurrentItem
Set vm_CurrentItem = vm_CurrentItem.nextItem
End Sub

Public Sub movePrevious()
Set vm_CurrentItem = vm_ReverseStack.pop
End Sub

Public Property Get currentItem() As Variant
Attribute currentItem.VB_UserMemId = 0
If Not vm_CurrentItem Is Nothing Then
    If IsObject(vm_CurrentItem.stackData) Then
        Set currentItem = vm_CurrentItem.stackData
    Else
        currentItem = vm_CurrentItem.stackData
    End If
Else
    currentItem = Empty
End If
End Property

Public Sub moveFirst()
Set vm_CurrentItem = vm_HeadItem
vm_ReverseStack.clear
End Sub

Public Sub moveLast()
While Me.hasNext
    moveNext
Wend
End Sub

Private Sub Class_Terminate()
Set vm_CurrentItem = Nothing
Set vm_HeadItem = Nothing
Set vm_ReverseStack = Nothing
End Sub
